package com.finai;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/***************************************
 * author:      zhangguoqing-phq
 * createDate:  2020/11/27 22:16
 * description: 描述信息
 ****************************************/
public class ToolsMenuUtil {
    private static final long serialVersionUID = 1L;
    private static TrayIcon trayIcon = null;
    static JFrame mf = new JFrame();
    static SystemTray tray = SystemTray.getSystemTray();

    public static void main(String[] args) {
        ToolsMenuUtil.miniTray();
        ToolsMenuUtil.miniTray2();
    }

    private static void miniTray() { // 窗口最小化到任务栏托盘

        ImageIcon trayImg = new ImageIcon("D:\\tmp\\kkk\\s5.png");// 托盘图标

        trayIcon = new TrayIcon(trayImg.getImage(), "信息防泄漏(DLP)系统终端", new PopupMenu());
        trayIcon.setImageAutoSize(true);

        trayIcon.addMouseListener(new MouseAdapter() {

            public void mouseClicked(MouseEvent e) {

                if (e.getClickCount() == 1) {// 单击 1 双击 2

                    //tray.remove(trayIcon);
                    //mf.setVisible(true);
                    mf.setExtendedState(JFrame.NORMAL);
                    mf.toFront();
                }

            }

        });

        try {

            tray.add(trayIcon);

        } catch (AWTException e1) {
            e1.printStackTrace();
        }

    }

    private static void miniTray2() { // 窗口最小化到任务栏托盘

        ImageIcon trayImg = new ImageIcon("D:\\tmp\\kkk\\360.png");// 托盘图标

        trayIcon = new TrayIcon(trayImg.getImage(), "奇安信天擎", new PopupMenu());
        trayIcon.setImageAutoSize(true);

        trayIcon.addMouseListener(new MouseAdapter() {

            public void mouseClicked(MouseEvent e) {

                if (e.getClickCount() == 1) {// 单击 1 双击 2

                    //tray.remove(trayIcon);
                    //mf.setVisible(true);
                    mf.setExtendedState(JFrame.NORMAL);
                    mf.toFront();
                }

            }

        });

        try {

            tray.add(trayIcon);

        } catch (AWTException e1) {
            e1.printStackTrace();
        }

    }


    public static void myFrame() { // 窗体

        mf.setLocation(300, 100);
        mf.setSize(500, 300);
        mf.setTitle("hello world");
        mf.setVisible(true);// 使窗口可见

        mf.addWindowListener(new WindowAdapter() { // 窗口关闭事件
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            };

            public void windowIconified(WindowEvent e) { // 窗口最小化事件

                mf.setVisible(false);
                ToolsMenuUtil.miniTray();
                ToolsMenuUtil.miniTray2();

            }

        });

    }

}
